package com.zjr.db;

import java.sql.*;

public class DBConnection {
	private static String driverClass = "com.mysql.jdbc.Driver";
	private static String url = "jdbc:mysql:///usermanager?useUniCode=true&charactorEncoding=UTF-8&useSSL=false";
	private static String username = "root";
	private static String password = "1234";
	
	static{
		try {
			Class.forName(driverClass);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() throws SQLException{
		return DriverManager.getConnection(url,username, password);
	}
	
	public static void Close(ResultSet rs, Statement stmt, Connection conn){
		closeResultSet(rs);
		closeStatement(stmt);
		closeConnection(conn);
	}
	
	public static void closeConnection(Connection conn){
		if(conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			conn = null;
		}
	}
	
	public static void closeStatement(Statement stmt){
		if(stmt != null){
			try {
				stmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			stmt = null;
		}
	}
	
	public static void closeResultSet(ResultSet rs){
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			rs = null;
		}
	}
}
